package com.xiaoma.chat.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dexcoder.assistant.persistence.JdbcDao;
import com.xiaoma.chat.domain.ChatRm;
import com.xiaoma.chat.domain.User;

@Service
public class UserService {

    @Autowired
    private JdbcDao jdbcDao;
    
    public User findUser(String name, int organizationId) {
        User entity = new User();
        entity.setName(name);
        entity.setOrganizationId(organizationId);
        User user = jdbcDao.querySingleResult(entity);
        return user;
    }
    
    public void updateUser(User user) {
        jdbcDao.update(user);
    }
    
    public Integer insertUser(User user) {
        return jdbcDao.insert(user);
    }
    
    public User getById(int id) {
    	return jdbcDao.get(User.class, id);
    }
    
    public void saveChatRm(ChatRm chatRm) {
        jdbcDao.save(chatRm);
    }
    
    public void deleteChatRm(int studentId, int groupId) {
        ChatRm chatRm = new ChatRm();
        chatRm.setStudentId(studentId);
        chatRm.setGroupId(groupId);
        jdbcDao.delete(chatRm);
    }
    
    public List<ChatRm> findChatRms(Integer teacherId, Integer studentId, Integer groupId) {
        ChatRm chatRm = new ChatRm();
        chatRm.setStudentId(studentId);
        chatRm.setTeacherId(teacherId);
        chatRm.setGroupId(groupId);
        return jdbcDao.queryList(chatRm);
    }
    
    
}
